package com.boolib.service.impl;

import com.boolib.commons.entity.ServerResponse;
import com.boolib.commons.util.ServerResponseUtil;
import com.boolib.dao.ShopSkuKeyMapper;
import com.boolib.pojo.ShopSkuKey;
import com.boolib.pojo.ShopSkuKeyExample;
import com.boolib.service.IProductSkuKeyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ProductSkuKeyServiceImpl implements IProductSkuKeyService {


    @Autowired
    private  ShopSkuKeyMapper shopSkuKeyMapper;


    @Override
    public ServerResponse selectSkuKeyUserProductIdOrderBySortASC(Integer productId) {

        ServerResponse serverResponse= ServerResponseUtil.argumentCheck(productId);

        if(serverResponse.isSuccess()) return  serverResponse;

        ShopSkuKeyExample shopSkuKeyExample = new ShopSkuKeyExample();

        ShopSkuKeyExample.Criteria criteria = shopSkuKeyExample.createCriteria();
        /**
         * spuid = productid
         */
        criteria.andSpuIdEqualTo(productId);

        shopSkuKeyExample.setOrderByClause("sort ASC");


        return ServerResponse.createBySuccess( shopSkuKeyMapper.selectByExample(shopSkuKeyExample));
    }
}
